export default function createStore(reducer, enhancer) {

      if(enhancer){
            return enhancer(createStore)(reducer);
      }

      // 存放监听回调的地方
      let listeners = [];

      // 数据存放位置
      let currentState;

      function subscribe(listener) {
            listeners.push(listener);


            return () => { 
                  listeners =  listeners.filter(prop => prop !== listener);
            }
      }

      function dispatch(actions) {
            currentState = reducer(currentState, actions);
            listeners.forEach(listener => listener())
      }

      function getState() {
            return currentState;
      }

      dispatch({type: ""});

      return {
            getState,
            dispatch,
            subscribe,
      };
}
